package com.dvnchina.boss;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class ReadFileForUpdate
{
  public Map map1 = new HashMap();
  public Map map2 = new HashMap();
  public Map map3 = new HashMap();

  public static void main(String[] args) {
    String fileUrl = "D:\\1.txt";
    String url2 = "D:\\2.txt";
    ReadFileForUpdate ru = new ReadFileForUpdate();
    ru.readFile(fileUrl);
    ru.readFile2(url2);
    List list1 = ru.compareMap();
    for (int j = 0; j < list1.size(); j++);
    ru.printInsert(list1);
  }

  public void readFile(String fileUrl) {
    try {
      BufferedReader rd = new BufferedReader(new FileReader(new File(fileUrl)));
      String str = null;
      while (rd.read() != -1) {
        str = rd.readLine();

        String result = "";
        result = getStr(str);
        result.equals("");
      }

    }
    catch (FileNotFoundException e)
    {
      e.printStackTrace();
    }
    catch (IOException e) {
      e.printStackTrace();
    }
  }

  public String getStr(String str) {
    int num1 = 0;
    int num2 = 0;
    int num3 = 0;
    int num4 = 0;
    String returnstr = "";
    if (((num1 = str.indexOf("IC卡换成")) != -1) && ((num2 = str.indexOf("机顶盒换成")) != -1) && ((num3 = str.indexOf("】,业")) != -1)) {
      String s1 = "";
      String s2 = "";
      String s3 = "";
      s1 = str.substring(num1 + 6, num2 - 2);
      s2 = str.substring(num2 + 6, num3);
      s3 = str.substring(0, 6).trim();

      returnstr = s3 + ":" + s1 + ";" + s2;
      putMap(this.map1, returnstr);
    }
    if (((num4 = str.indexOf("2015007")) != -1) && (str.indexOf("当") <= 0))
    {
      returnstr = str.substring(0, 6).trim() + ":" + str.substring(num4 + 7, str.length()).trim();
      putMap(this.map2, returnstr);
    }
    return returnstr;
  }

  public void putMap(Map map12, String str) {
    String[] arrs = str.split(":");
    map12.put(arrs[0], arrs[1]);
  }
  public List compareMap() {
    List list = new ArrayList();
    for (Iterator it = this.map1.keySet().iterator(); it.hasNext(); ) {
      String s1 = (String)it.next();
      for (Iterator it2 = this.map2.keySet().iterator(); it2.hasNext(); ) {
        String s2 = (String)it2.next();
        if (!s1.equals(s2))
          continue;
        list.add(s1 + ";" + this.map1.get(s1) + ";" + this.map2.get(s2));
      }

    }

    return list; } 
  // ERROR //
  public void readFile2(String url) { // Byte code:
    //   0: new 65	java/io/BufferedReader
    //   3: dup
    //   4: new 67	java/io/FileReader
    //   7: dup
    //   8: new 69	java/io/File
    //   11: dup
    //   12: aload_1
    //   13: invokespecial 71	java/io/File:<init>	(Ljava/lang/String;)V
    //   16: invokespecial 73	java/io/FileReader:<init>	(Ljava/io/File;)V
    //   19: invokespecial 76	java/io/BufferedReader:<init>	(Ljava/io/Reader;)V
    //   22: astore_2
    //   23: lconst_0
    //   24: lstore_3
    //   25: ldc 83
    //   27: astore 5
    //   29: goto +42 -> 71
    //   32: aload_2
    //   33: invokevirtual 79	java/io/BufferedReader:readLine	()Ljava/lang/String;
    //   36: astore 5
    //   38: aload 5
    //   40: ldc 216
    //   42: invokevirtual 167	java/lang/String:split	(Ljava/lang/String;)[Ljava/lang/String;
    //   45: astore 6
    //   47: aload_0
    //   48: getfield 21	com/dvnchina/boss/ReadFileForUpdate:map3	Ljava/util/Map;
    //   51: aload 6
    //   53: iconst_1
    //   54: aaload
    //   55: invokevirtual 127	java/lang/String:trim	()Ljava/lang/String;
    //   58: aload 6
    //   60: iconst_0
    //   61: aaload
    //   62: invokevirtual 127	java/lang/String:trim	()Ljava/lang/String;
    //   65: invokeinterface 171 3 0
    //   70: pop
    //   71: aload_2
    //   72: invokevirtual 95	java/io/BufferedReader:read	()I
    //   75: i2l
    //   76: dup2
    //   77: lstore_3
    //   78: ldc2_w 218
    //   81: lcmp
    //   82: ifne -50 -> 32
    //   85: goto +16 -> 101
    //   88: astore_2
    //   89: aload_2
    //   90: invokevirtual 98	java/io/FileNotFoundException:printStackTrace	()V
    //   93: goto +8 -> 101
    //   96: astore_2
    //   97: aload_2
    //   98: invokevirtual 103	java/io/IOException:printStackTrace	()V
    //   101: return
    //
    // Exception table:
    //   from	to	target	type
    //   0	85	88	java/io/FileNotFoundException
    //   0	85	96	java/io/IOException 
	  } 
  public void printInsert(List list) { List returnList = new ArrayList();
    for (Iterator it = this.map3.keySet().iterator(); it.hasNext(); ) {
      String key = (String)it.next();
      for (int i = 0; i < list.size(); i++) {
        String s = list.get(i).toString().split(";")[3];
        if (key.equals(s)) {
          returnList.add(list.get(i).toString() + ";" + this.map3.get(key));
        }
      }
    }
    for (int i = 0; i < returnList.size(); i++)
    {
      String[] arrs = returnList.get(i).toString().split(";");
      String sql1 = "insert into bs_tb_cust_interaction_detail values(" + arrs[0].toString().trim() + ",2015003,'AAA-设备无法修复');";
      String sql2 = "insert into bs_tb_cust_interaction_detail values(" + arrs[0].toString().trim() + ",2015004,'补充数据');";
      String sql3 = "insert into bs_tb_cust_interaction_detail values(" + arrs[0].toString().trim() + ",2015005,'3');";
      String sql4 = "insert into bs_tb_cust_interaction_detail values(" + arrs[0].toString().trim() + ",2015008,'" + arrs[4].toString().trim() + "');";
      String sql5 = "insert into bs_tb_cust_interaction_detail values(" + arrs[0].toString().trim() + ",2015009,'" + arrs[1].toString().trim() + "');";
      String sql6 = "insert into bs_tb_cust_interaction_detail values(" + arrs[0].toString().trim() + ",2015010,'" + arrs[2].toString().trim() + "');";
      System.out.println("------CUST_INTER_ID=" + arrs[0].toString().trim() + "---");
      System.out.println(sql1);
      System.out.println(sql2);
      System.out.println(sql3);
      System.out.println(sql4);
      System.out.println(sql5);
      System.out.println(sql6);
    }

    System.out.println("-- --------备份语句，有错误是删除-------");
    for (int i = 0; i < returnList.size(); i++) {
      String[] arrs = returnList.get(i).toString().split(";");
      String delsql = "delete from bs_tb_cust_interaction_detail where cust_inter_id=" + arrs[0].toString().trim() + " and INTERACTION_ITEM_ID=2015003;";
      String delsql1 = "delete from bs_tb_cust_interaction_detail where cust_inter_id=" + arrs[0].toString().trim() + " and INTERACTION_ITEM_ID=2015004;";
      String delsql2 = "delete from bs_tb_cust_interaction_detail where cust_inter_id=" + arrs[0].toString().trim() + " and INTERACTION_ITEM_ID=2015005;";
      String delsql3 = "delete from bs_tb_cust_interaction_detail where cust_inter_id=" + arrs[0].toString().trim() + " and INTERACTION_ITEM_ID=2015008;";
      String delsql4 = "delete from bs_tb_cust_interaction_detail where cust_inter_id=" + arrs[0].toString().trim() + " and INTERACTION_ITEM_ID=2015009;";
      String delsql5 = "delete from bs_tb_cust_interaction_detail where cust_inter_id=" + arrs[0].toString().trim() + " and INTERACTION_ITEM_ID=2015010;";
      System.out.println("------CUST_INTER_ID=" + arrs[0].toString().trim() + "---");
      System.out.println(delsql);
      System.out.println(delsql1);
      System.out.println(delsql2);
      System.out.println(delsql3);
      System.out.println(delsql4);
      System.out.println(delsql5);
    }
  }
}